//
//  HRZOrderFootCell.m
//  EMarket
//
//  Created by 石头 on 2018/10/11.
//  Copyright © 2018 好日子. All rights reserved.
//

#import "HRZOrderFootCell.h"
// Controllers

// Models
#import "HRZOrderModel.h"
#import "HRZOrderGoodsDetailModel.h"
// Views

// Vendors

// Categories

// Others
#import "HRZSpeedy.h"

@interface HRZOrderFootCell()
{
    id _target;
    SEL _action;
}

@property (nonatomic, strong) UILabel *mOrderDes;
@property (nonatomic, strong) UIButton *mConfirmBtn;

@end

@implementation HRZOrderFootCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.mOrderDes];
        [self addSubview:self.mConfirmBtn];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)layoutSubviews {
    
    [self.mConfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(self).mas_offset(-10);
    }];
    
    [self.mOrderDes mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(self.mConfirmBtn.mas_left).mas_offset(-5);
    }];
    
}
#pragma mark - Delegate


#pragma mark - EventResponse
- (void)onConfirmBtnClick {
    if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectdComfirmBtnWithCell:)]) {
        [self.delegate didSelectdComfirmBtnWithCell:self];
    }
}

#pragma mark - Getter/Setter
- (void)setModel:(HRZOrderModel *)model {
    _model = model;

    CGFloat totalPrice = 0.0;
    for (HRZOrderGoodsDetailModel *goodsModel in _model.orderDetailDtos) {
        totalPrice += [goodsModel.goodsPrice floatValue] * [goodsModel.goodsNumber intValue];
    }
    _mOrderDes.text = [NSString stringWithFormat:@"总计商品%lu种 共计:¥%.2f", (unsigned long)_model.orderDetailDtos.count, totalPrice];
}

- (void)setIsShowBtn:(BOOL)isShowBtn {
    
    self.mConfirmBtn.hidden = !isShowBtn;
    
}

- (UILabel *)mOrderDes{
    if (!_mOrderDes) {
        _mOrderDes = [[UILabel alloc] init];
        _mOrderDes.font = PFR14Font;
        _mOrderDes.textColor = [UIColor darkGrayColor];
    }
    return _mOrderDes;
}

- (UIButton *)mConfirmBtn{
    if (!_mConfirmBtn) {
        
        _mConfirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_mConfirmBtn setTitle:@"确认收货" forState:UIControlStateNormal];
        [_mConfirmBtn addTarget:self action:@selector(onConfirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [_mConfirmBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        
        _mConfirmBtn.titleLabel.font = PFR13Font;
        _mConfirmBtn.layer.borderWidth = .5;
        _mConfirmBtn.layer.borderColor = [UIColor orangeColor].CGColor;
        _mConfirmBtn.layer.cornerRadius = 5;
        [_mConfirmBtn setContentEdgeInsets:UIEdgeInsetsMake(3, 6, 3, 6)];
    }
    return _mConfirmBtn;
}

@end
